package com.yt.order.api.client;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;

/**
 * 号码查询控制器
 */
@RestController
@RequestMapping("/api/phone")
public class PhoneController {
    
    /**
     * 模拟数据库查询，根据输入号码查找对应的目标号码
     */
    @PostMapping("/query")
    public Map<String, Object> queryTargetPhone(@RequestBody Map<String, String> request) {
        Map<String, Object> response = new HashMap<>();
        
        String inputPhone = request.get("phone");
        if (inputPhone == null || inputPhone.isEmpty()) {
            response.put("success", false);
            response.put("message", "请输入号码");
            return response;
        }
        
        // 模拟数据库查询，实际项目中应查询真实数据库
        // 这里简单处理，建立一些测试号码的关联关系
        Map<String, String> phoneRelation = new HashMap<>();
        phoneRelation.put("13800138000", "13900139000");
        phoneRelation.put("13900139000", "13800138000");
        phoneRelation.put("13700137000", "13600136000");
        phoneRelation.put("13600136000", "13700137000");
        
        String targetPhone = phoneRelation.get(inputPhone);
        if (targetPhone != null) {
            response.put("success", true);
            response.put("targetPhone", targetPhone);
        } else {
            response.put("success", false);
            response.put("message", "未找到对应的号码");
        }
        
        return response;
    }
}
